package com.itruth.data.dao;


import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DraftDao {
	
	/**
	 * replace方法必须更新全部字段才有效，否则与insert无异
	 * @param draft
	 */
	public static void saveDraft(String draft) {
		
		SQLiteDatabase db = DbHelper.getIns().getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put("content", draft);
		//草稿表中只有一条数据
		values.put("id", 1);
		db.replace("draft", "content", values);
		db.close();
		
	}
	
	public static String queryDraft() {
		
		String draft = null;
		
		SQLiteDatabase db = DbHelper.getIns().getReadableDatabase();
		
		Cursor cursor = db.rawQuery("select content from draft where id = ? ", new String[]{"1"});
		
		if (cursor.moveToFirst()) {
			draft = cursor.getString(cursor.getColumnIndex("content"));
		}
		
		return draft;
		
	}
	
}
